import { Module, Global } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { OSSService } from './oss.service';

@Global()
@Module({
  imports: [ConfigModule],
  providers: [
    {
      provide: OSSService,
      useFactory: (configService: ConfigService) => {
        return new OSSService({
          accessKeyId: configService.get('aliyun.accessKeyId'),
          accessKeySecret: configService.get('aliyun.accessKeySecret'),
          region: configService.get('aliyun.ossRegion'),
          bucket: configService.get('aliyun.ossBucket'),
        });
      },
      inject: [ConfigService],
    },
  ],
  exports: [OSSService],
})
export class OSSModule {}
